package com.power.sifa.approve.executor.impl;

import com.power.sifa.approve.model.Apl_admre_audit;
import com.power.sifa.approve.model.Apl_admreview;
import com.power.sifa.approve.service.Apl_admre_auditService;
import com.power.sifa.approve.service.Apl_admreviewService;
import com.power.sifa.approve.service.Apl_mainService;
import com.power.sifa.util.executor.AbstractPostExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
@Component
@Slf4j
public class AdmreUpdateQuedate extends AbstractPostExecutor {

    // 用户id
    private String userid;
    // 环节分类标识
    private String category;
    // 用户名
    private String username;
    // 单位id
    private String sectionid;
    // 单位名称
    private String sectionname;
    // 部门id
    private String deptid;
    // 部门名称
    private String deptname;
    // 处理意见
    private String remark;
    // 行政区划
    private String adid;
    // 环节名称
    private String taskname;


    @Resource
    private Apl_admreviewService apl_admreviewService;
    @Resource
    private Apl_admre_auditService apl_admre_auditService;

    @Override
    public void init(Map<String, Object> initdata) {
        this.userid = (String) initdata.get("userid");
        this.category = (String) initdata.get("category");
        this.username = (String) initdata.get("username");
        this.sectionid = (String) initdata.get("sectionid");
        this.sectionname = (String) initdata.get("sectionname");
        this.deptid = (String) initdata.get("deptid");
        this.deptname = (String) initdata.get("deptname");
        this.remark = (String) initdata.get("remark");
        this.adid = (String) initdata.get("adid");
        this.taskname = (String) initdata.get("taskname");
    }

    @Override
    public Map<String, Object> execute() throws Exception {
        Apl_admre_audit auditObj = this.apl_admre_auditService.getById(super.applyid);
        Apl_admreview admreviewObj = this.apl_admreviewService.getById(auditObj.getApplyid());
        if(!auditObj.getQuedate().equals(admreviewObj.getQuedate())) {
            // 更新主流程和所有子流程的期满日期
            this.apl_admreviewService.updateQuedate(auditObj.getApplyid(), auditObj.getQuedate());
            this.apl_admre_auditService.updateQuedate(auditObj.getApplyid(), auditObj.getQuedate());
        }
        return null;
    }
}
